package com.suarte.core;

import org.appfuse.model.BaseObject;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

import com.suarte.core.service.PaymentStatus;
import java.util.ArrayList;
import org.appfuse.model.User;

/**
 * Created by IntelliJ IDEA.
 * User: Gcastillo
 * Date: Dec 30, 2010
 * Time: 4:22:15 PM
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "sa_payments")
public class Payment extends BaseObject {

    private Long id;
    private List<InvoicePayment> paymentDetails = new ArrayList();
    private Date date;
    private Company company;
    private PaymentType type;
    private Currency currency;
    private Currency exchangeCurrency;
    private Float exchangeRate;
    private Float equivalentAmount;
    private String description;
    private String receiptNumber;
    private Float amount = 0f;
    private Float localAmount;
    private Float foreignAmount;
    private PaymentStatus status = PaymentStatus.APLICADO;
    private User createdBy;
    private Date createdOn = new Date();
    private User modifiedBy;
    private Date modifiedOn = new Date();
    private Bank bank;
    private String paymentNumber;

    public Payment() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PAYMENT_SEQ")
    @SequenceGenerator(name = "PAYMENT_SEQ", sequenceName = "PAYMENT_SEQ", allocationSize = 1)
    public Long getId() {
        return id;
    }

    @OneToMany(mappedBy = "payment", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    public List<InvoicePayment> getPaymentDetails() {
        return paymentDetails;
    }

    @Column(name = "payment_date")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getDate() {
        return date;
    }

    @ManyToOne
    @JoinColumn(name = "company_id")
    public Company getCompany() {
        return company;
    }

    @ManyToOne
    @JoinColumn(name = "payment_type_id")
    public PaymentType getType() {
        return type;
    }

    @ManyToOne
    @JoinColumn(name = "currency_id")
    public Currency getCurrency() {
        return currency;
    }

    @ManyToOne
    @JoinColumn(name = "exchange_currency_id")
    public Currency getExchangeCurrency() {
        return exchangeCurrency;
    }

    @Column(name = "exchange_rate")
    public Float getExchangeRate() {
        return exchangeRate;
    }

    @Column(name = "equivalent_amount")
    public Float getEquivalentAmount() {
        return equivalentAmount;
    }

    @Column(name = "local_amount")
    public Float getLocalAmount() {
        return localAmount;
    }

    @Column(name = "foreign_amount")
    public Float getForeignAmount() {
        return foreignAmount;
    }

    @Column(name = "description")
    public String getDescription() {
        return description;
    }

    @Column(name = "receipt_number")
    public String getReceiptNumber() {
        return receiptNumber;
    }

    @Column(name = "amount")
    public Float getAmount() {
        return amount;
    }

    @Enumerated(EnumType.STRING)
    @Column(name = "status")
    public PaymentStatus getStatus() {
        return status;
    }

    @ManyToOne
    @JoinColumn(name = "created_by")
    public User getCreatedBy() {
        return createdBy;
    }

    @ManyToOne
    @JoinColumn(name = "modified_by")
    public User getModifiedBy() {
        return modifiedBy;
    }

    @Column(name = "created_on")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getCreatedOn() {
        return createdOn;
    }

    @Column(name = "modified_on")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getModifiedOn() {
        return modifiedOn;
    }

    @ManyToOne
    @JoinColumn(name = "bank_id")
    public Bank getBank() {
        return bank;
    }    
    
    @Column(name = "payment_number")
    public String getPaymentNumber() {
        return paymentNumber;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setPaymentDetails(List<InvoicePayment> paymentDetails) {
        this.paymentDetails = paymentDetails;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public void setType(PaymentType type) {
        this.type = type;
    }

    public void setCurrency(Currency currency) {
        this.currency = currency;
    }

    public void setExchangeCurrency(Currency exchangeCurrency) {
        this.exchangeCurrency = exchangeCurrency;
    }

    public void setExchangeRate(Float exchangeRate) {
        this.exchangeRate = exchangeRate;
    }

    public void setEquivalentAmount(Float equivalentAmount) {
        this.equivalentAmount = equivalentAmount;
    }

    public void setLocalAmount(Float localAmount) {
        this.localAmount = localAmount;
    }

    public void setForeignAmount(Float foreignAmount) {
        this.foreignAmount = foreignAmount;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setReceiptNumber(String receiptNumber) {
        this.receiptNumber = receiptNumber;
    }

    public void setAmount(Float amount) {
        this.amount = amount;
    }

    public void setStatus(PaymentStatus status) {
        this.status = status;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    public void setModifiedBy(User modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public void setModifiedOn(Date modifiedOn) {
        this.modifiedOn = modifiedOn;
    }

    public void addPaymentDetail(InvoicePayment detail) {
        this.paymentDetails.add(detail);
    }

    public void setBank(Bank bank) {
        this.bank = bank;
    }
    
    public void setPaymentNumber(String paymentNumber) {
        this.paymentNumber = paymentNumber;
    }

    @Override
    public String toString() {
        return description;
    }

    @Override
    public boolean equals(Object other) {
        if (other == this) {
            return true;
        }
        if (!(other instanceof Payment)) {
            return false;
        }
        Payment _i = (Payment) other;
        return id.equals(_i.id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}
